/**
 * related to sendui.ui
 * 
 * @Author : mafeng1122
 * @Timestamp : 2017-11-15
 */
var dialog  = sm("do_Dialog")
var do_DataCache = sm("do_DataCache");//sp
var nf = sm("do_Notification");

// combox
var renwuzhicheng_combox = ui("do_ComboBox_3");
var renwumingcheng_combox = ui("do_ComboBox_4");

var sure_button = ui("do_Button_4");
var cancle_button = ui("do_Button_3");

var renwuzhicheng_data;
var renwumingcheng_data;

var http = mm("do_Http");
	http.method = "GET";
	http.timeout = 10000;
	http.contentType = "application/x-www-form-urlencoded";
	http.url = encodeURI(do_DataCache.loadData("baseUrl") +"GetChooseValue?view="+ "发送工单岗位范围" +"&where=");
	deviceone.print(http.url);
	http.on("success", function(data, e) {
		var jsonString = data.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">","");
		jsonString = jsonString.replace("</string>","");
		deviceone.print(jsonString);
		var bean = JSON.parse(jsonString);
		deviceone.print(bean.result);
		if (bean.result==200) {
			var items = "";
			renwuzhicheng_data = bean["returnObj"];
			for (var i = 0; i < bean["returnObj"].length; i++) {
				
				if (i == bean["returnObj"].length - 1) {
					items = items + bean["returnObj"][i]["text"]
					deviceone.print(items)
				} else {
					items = items + bean["returnObj"][i]["text"] + ",";
					deviceone.print(items)
				}
			}
			renwuzhicheng_combox.items = items
		}else {
			nf.toast(bean.msg);
		}
	});
	http.on("fail", function(data, e) {
		deviceone.print(JSON.stringify(data));
		nf.toast("网络问题");
	});
	http.request();

	
	renwuzhicheng_combox.on("selectChanged", function(data, e) {
		
		var http = mm("do_Http");
		http.method = "GET";
		http.timeout = 10000;
		http.contentType = "application/x-www-form-urlencoded";
		http.url = encodeURI(do_DataCache.loadData("baseUrl") +"GetChooseValue?view="+ "vw_sys_user" +"&where=Post_id ="+ renwuzhicheng_data[renwuzhicheng_combox.index].id);
		deviceone.print(http.url);
		http.on("success", function(data, e) {
			var jsonString = data.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">","");
			jsonString = jsonString.replace("</string>","");
			deviceone.print(jsonString);
			var bean = JSON.parse(jsonString);
			deviceone.print(bean.result);
			if (bean.result==200) {
				var items = "";
				renwumingcheng_data = bean["returnObj"];
				for (var i = 0; i < bean["returnObj"].length; i++) {
					
					if (i == bean["returnObj"].length - 1) {
						items = items + bean["returnObj"][i]["User_name"]
						deviceone.print(items)
					} else {
						items = items + bean["returnObj"][i]["User_name"] + ",";
						deviceone.print(items)
					}
				}
				renwumingcheng_combox.items = items
			}else {
				nf.toast(bean.msg);
			}
		});
		http.on("fail", function(data, e) {
			deviceone.print(JSON.stringify(data));
			nf.toast("网络问题");
		});
		http.request();
		
	})

sure_button.on("touch", function (data) {
	// 发送
	var loginer = do_DataCache.loadData("loginer");
	deviceone.print(JSON.stringify(do_DataCache.loadData("loginer")))
	var http = mm("do_Http");
	http.method = "GET";
	http.timeout = 10000;
	http.contentType = "application/x-www-form-urlencoded";
	http.url = encodeURI(do_DataCache.loadData("baseUrl") +"GetChooseValue?view="+ "vw_sys_user" +"&where=Post_id ="+ renwuzhicheng_data[renwuzhicheng_combox.index].id);
	deviceone.print(http.url);
	http.on("success", function(data, e) {
		var jsonString = data.replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<string xmlns=\"http://tempuri.org/\">","");
		jsonString = jsonString.replace("</string>","");
		deviceone.print(jsonString);
		var bean = JSON.parse(jsonString);
		deviceone.print(bean.result);
		if (bean.result==200) {
			
		}else {
			nf.toast(bean.msg);
		}
	});
	http.on("fail", function(data, e) {
		deviceone.print(JSON.stringify(data));
		nf.toast("网络问题");
	});
	http.request();

});
	
cancle_button.on("touch", function (data) {
	dialog.close();
})



